package com.isoftstone.disk.controller;

import com.isoftstone.disk.entity.FileInfoTreeEntity;
import com.isoftstone.disk.service.DiskService;
import com.isoftstone.platform.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.logging.Logger;

@Controller
@RequestMapping("/gdpinfo")
public class ZtreeController  extends BaseController {
    private Logger logger = Logger.getLogger("ZtreeController");

    @Resource
    private DiskService diskService;

    @RequestMapping("/page")
    public String ShowRecycleFiles(){
        return  "file/kaifa";
    }

    @RequestMapping("/queryFileInfoZtreeList")
    @ResponseBody
    public List<FileInfoTreeEntity> queryFileInfoZtreeList(String roleuuid){
        List<FileInfoTreeEntity> list = diskService.queryFileInfoZtreeList(roleuuid);
        return list;
    }

    @RequestMapping(value = "/move")
    @ResponseBody
    //才能返回对应的json字符串
    public String moveFile(@RequestParam("fileId")String id, @RequestParam("nodesIds") String[] ps) {
        logger.info(id);
        for(String i:ps) {
            logger.info(i);
        }
        if(ps.length==0){
            return buildSuccessJsonMsg("role.cancel.sucess", null);
        }
        //id 为 选择的文件id    ps为选中的文件夹
        diskService.moveFile(id,ps);
        return buildSuccessJsonMsg("role.grant.sucess", null);
    }

    @RequestMapping(value = "/copy")
    @ResponseBody
    //才能返回对应的json字符串
    public String copyFile(@RequestParam("fileId")String id, @RequestParam("nodesIds") String[] ps) {
        logger.info(id);
        for(String i:ps) {
            logger.info(i);
        }
        if(ps.length==0){
            return buildSuccessJsonMsg("role.cancel.sucess", null);
        }
        //id 为 选择的文件id    ps为选中的文件夹
        diskService.copyFile(id,ps);
        return buildSuccessJsonMsg("role.grant.sucess", null);
    }
}